home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / macpaintController.m < prev    next >
Text File  |  1995-06-12  |  7KB  |  190 lines

  1. /***********************************************************************\
  2. Controller class for Convert MacPaint which converts MacPaint files to PostScript files.
  3. Copyright (C) 1993 David John Burrowes
  4.  
  5. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
  6.  
  7. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  8.  
  9. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  10.  
  11. The author, David John Burrowes, can be reached at:
  12.     davidjohn@kira.net.netcom.com
  13.     David John Burrowes
  14.     1926 Ivy #10
  15.     San Mateo, CA 94403-1367
  16. \***********************************************************************/
  17.  
  18.  
  19. #import "macpaintController.h"
  20. #import <stdio.h>
  21. #import <libc.h>            // for mkdir
  22. #import    <string.h>        // for strrchr
  23. #include <sys/vnode.h>
  24. #import "PSFile.h"
  25. #import "macpaintConverter.h"
  26. #import <appkit/Matrix.h>    // For matrix stuff for preferences setting
  27. #import <appkit/Cell.h>    // for menu command work
  28.  
  29. @implementation macpaintController
  30.  
  31.  
  32. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. //    Routine:        init
  34. //    Parameters:    none
  35. //    Returns:        self
  36. //    Stores:        none
  37. //    Description:
  38. //        This overrides the defalut init method.  The purpose of this overriding
  39. //        is to give ourselves a chance to set up some internal variables which are used
  40. //        later on
  41. //    Bugs:
  42. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. - init
  44. {    
  45.     static NXDefaultsVector theDefaults =
  46.     {
  47.         {"DoPacking", "YES"},
  48.         {NULL, NULL}
  49.     };
  50.  
  51.     [super init];
  52.  
  53.     ConversionString = "Converting MacPaint file";
  54.     SourcePrompt = "Paint file:";
  55.     DestPrompt = "eps file:";
  56.     DestExtension = ".eps";
  57.     DefaultsOwner = "MacPaint_to_eps";
  58.  
  59.     NXRegisterDefaults(DefaultsOwner, theDefaults);
  60.     
  61.     PackTheImage = [self   GetBoolPref: "DoPacking"];
  62.  
  63.     converterInst = [[macpaintConverter   alloc]  init];
  64.  
  65.     return self;
  66. }
  67.  
  68.  
  69.  
  70. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. //    Routine:        displayPreferences: 
  72. //    Parameters:    the object that called us
  73. //    Description:
  74. //    This is called whenever we need to bring the preferences panel onto the screen.
  75. //    Using the value in our internal PackTheImage variable, then we set the buttons
  76. //    in the preference panel to reflect these, and then we show the panel.
  77. //    Bugs:
  78. //        Well, strictly speaking, this is only needed the first time this is called,
  79. //        because thereafter the buttons maintain their own highlite properly.
  80. //        Oh well.  This whole scheme is a bit awkward, given my trivial use, and the fact
  81. //        that it really seems to be designed for bigger things.
  82. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  83. -displayPreferences: sender
  84. {
  85.     //
  86.     //    Get the default preference values, and compare judge what buttons to
  87.     //    highlight for the user.
  88.     //
  89.     if (PackTheImage == YES)
  90.         [PackingButton  selectCellWithTag: 1];
  91.     else
  92.         [PackingButton  selectCellWithTag: 0];
  93.     [prefPanel    makeKeyAndOrderFront:self];
  94.     return self;
  95. }
  96.  
  97.  
  98. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  99. //    Routine: ChangePacking: 
  100. //    Parameters: the object that called us
  101. //    Description:
  102. //        This method gets called whenever the user clicks on a button to change
  103. //        the setting of whether the output should be packed or not.  If the button they
  104. //        clicked on had a key of '1', then we will pack the image, otherwise we don't.
  105. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  106. -ChangePacking: target
  107. {
  108.     if ( [[target selectedCell] tag] == 1)
  109.         PackTheImage = YES;
  110.     else
  111.         PackTheImage = NO;
  112.  
  113.     [self   SetBoolPref: "DoPacking" To: PackTheImage];
  114.  
  115.     return self;
  116. }
  117.  
  118.  
  119.  
  120. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. //    Routine:        openDestFile
  122. //    Parameters:    the path to the file to be opened
  123. //    Returns:        the opened file object
  124. //    Stores:        none
  125. //    Description:
  126. //        This is used to open the destination file object (a PS file).  This is needed so
  127. //        that our superclass, when it is doing some of the work that we don' want to,
  128. //        will open an instance of the right class.
  129. //    Bugs:
  130. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  131. - openDestFile: (roCString) theFile
  132. {    
  133.     Instance    fileInstance;
  134.     [self   ResetResults];
  135.     
  136.     fileInstance = [[PSFile alloc] initAndUse: theFile];
  137.     if ([fileInstance   GetErrorCode] == ERR_OK)
  138.         [fileInstance   CreateAndOpenFor: FILE_WRITE];
  139.     if ([fileInstance   GetErrorCode] != ERR_OK)
  140.     {
  141.         [self   StoreErrorCode: ERR_OPENFAILED
  142.             AndText: "We failed to open the file"];
  143.         [fileInstance   free];
  144.         fileInstance = NullInstance;
  145.     }
  146.     return fileInstance;
  147. }
  148.  
  149.  
  150.  
  151.  
  152. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  153. //    Routine:        ConvertFrom:To: 
  154. //    Parameters:    The file to be converted from, and the file to be converted to
  155. //    Returns:        self
  156. //    Stores:        error code
  157. //    Description:
  158. //        This merely acts (like the rest of this object) as a kinda minimal interface
  159. //        shell.  This merely creates the converting object, asks it to convert the stuff,
  160. //        stores whether there were any results, and returns.
  161. //    Bugs
  162. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  163. - ConvertFrom: sourceFile To: destinationFile
  164. {
  165.     CString    tempString;
  166.     
  167.     [super   ConvertFrom: sourceFile To: destinationFile];
  168.     [ConvertCommand    setEnabled: NO];
  169.     [converterInst   SetPacking: PackTheImage AndPath: AppHome];
  170.     [converterInst   Convert: sourceFile To: destinationFile];
  171.     [ConvertCommand    setEnabled: YES];
  172.     //
  173.     //    93.01.31    djb    YOW!!! I was not storing the error code here!!!
  174.     //
  175.     if ( [converterInst   GetErrorCode] < ERR_OK)
  176.     {
  177.         tempString =   [converterInst   GetErrorText];
  178.         [self   StoreErrorCode:  [converterInst   GetErrorCode]
  179.             AndText: tempString];
  180.         FreeCString(tempString);
  181.     }
  182.     else
  183.         [self   StoreErrorCode: ERR_OK
  184.             AndText: "Converted Successfully" ];
  185.  
  186.     return self;
  187. }
  188.  
  189. @end
  190.